<#assign basePath=request.contextPath />
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

	<#include '/common/common-css.html'>
</head>

<body>
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">
                <div class="ibox-content">
                    <form class="form-horizontal m-t" id="myForm">
                    	<input type="hidden" name="id" id="id" value="">
                    	<div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>上级机构：</label>
                            <div class="col-sm-8">
                                <select id="parent" name="parent" class="form-control"></select>
                            </div>
                        </div>
            			<div class="form-group">
                            <label class="col-sm-3 control-label"><sapn class="text-danger">* </sapn>名称：</label>
                            <div class="col-sm-8">
                                <input id="name" name="name" class="form-control" type="text" value="">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
            			<div class="form-group">
                            <label class="col-sm-3 control-label">描述：</label>
                            <div class="col-sm-8">
                                <input id="description" name="description" class="form-control" type="text" value="">
                                <span class="help-block m-b-none">
                                </span>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <#include '/common/common-js.html'>
    <script type="text/javascript">
    $().ready(function() {
    	var pId = "${organization.parent.id}";
    	
    	$.ajax({
			type: 'POST',
			url: '${basePath }/organization/others?t=' + Math.random(),
			data : {"id" : "${organization.id}"},
			dataType: 'json',
			success: function(data){
				if(data.error){
					layer.msg(data.msg,{icon:2,time:1000});
				}else{
					var html = '';
					$.each(data, function(dataIndex, d){
						html += '<option value='+ d.id + '>'+ d.name +'</option>';
					});
					$("#parent").append(html);
					$("#parent").val(pId);
				}
			},
			error:function(e) {
				console.log(e);
			}
		});
    	
    	$("#id").val("${organization.id}");
    	$("#name").val("${organization.name}");
    	$("#description").val("${organization.description}");
        var e = "<i class='fa fa-times-circle'></i> ";
        $("#myForm").validate({
            rules: {
            	name: {
                    required: !0
                }
            },
            messages: {
            	name: {
                    required: e + "请输入名称"
                }
            },
            submitHandler:function(form){
            	var data = {
            		"id" : $("#id").val(),
            		"pId" : $("#parent").val(),
	            	"name" : $("#name").val(),
	            	"description" : $("#description").val()
            	};
    			$.ajax({    
    		        type: "post",   
    		        url: "${basePath}/organization/edit?t=" + Math.random(),   
    		        data : data,
    		        dataType: "json",    
    		        success: function (data) { 
    		        	if(data.error){
    						layer.msg(data.msg,{icon:2,time:1000});
    					}else{
    						if(data == 1){
        		        		parent.table.ajax.reload();
        		            	var index = parent.layer.getFrameIndex(window.name);
        		        		parent.layer.close(index);
        		        		//重新异步加载树
        						parent.zTree.reAsyncChildNodes(null, "refresh");
        		        		parent.layer.msg('修改成功!',{icon:1,time:1000});
        		        	}
    					}
    		        },
    		        error:function(e) {
    					console.log(e);
    				}
    		    }) 
    		}
        }); 
    });
    
    function edit(){
    	$("#myForm").submit();
    }
    </script>
</body>
</html>


